<?php

namespace app\mec\controller;
use think\Db;
use app\admin\model\UserModel;
use app\admin\model\UserType;
use think\Session;

class Order extends Base
{

    /**
     * [index 用户列表]
     * @return [type] [description]
     * @author
     */
    public function index(){
        if(request()->isAjax ()){
            extract(input());
            $map = [];
            $fids = $this->getSonIDS();
            $map['order_fen_id'] = ['in',$fids];
            if(isset($key)&&$key!="")
            {
                $map['a.order_num|a.order_device_id|shop_name'] = ['like',"%" . $key . "%"];
            }
            if(isset($level)&&$level!="")
            {
                $map['a.order_status'] = $level;
            }
            if(isset($way)&&$way!="")
            {
                $map['a.order_way'] = $way;
            }
            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::table('up_order')->alias('a')
                ->join('up_area area','a.order_shi=area.district_id','LEFT')
                ->join('up_shop_device s','a.order_device_id=s.shop_device_id','LEFT')
                ->join('up_fenxiao f','s.shop_fid=f.fen_id','LEFT')
                ->where($map)
                ->count();
            $lists = Db::table('up_order')->alias('a')
                ->join('up_area area','a.order_shi=area.district_id','LEFT')
                ->join('up_shop_device s','a.order_device_id=s.shop_device_id','LEFT')
                ->join('up_fenxiao f','s.shop_fid=f.fen_id','LEFT')
                ->where($map)
                ->order('order_id desc')
                ->page($Nowpage, $limits)
                ->field('a.*,shop_id,shop_name,fen_id,fen_realname,shop_fid,district')
                ->select();//计算总页面
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch("order/index");
    }


    /**
     * [userAdd 添加用户]
     * @return [type] [description]
     * @author
     */
    public function seeInfo()
    {
        $id = input('param.id');
        $user = Db::table('up_order')->alias('a')
            ->join('up_area area','a.order_shi=area.district_id','LEFT')
            ->join('up_shop_device s','a.order_device_id=s.shop_device_id','LEFT')
            ->join('up_fenxiao f','s.shop_fid=f.fen_id','LEFT')
            ->where('order_id',$id)
            ->find();
        $infos = Db::table('up_order_info')->alias('a')
            ->join('up_fenxiao f','a.info_fen_id=f.fen_id','LEFT')
            ->where('info_order_id',$id)
            ->order('info_level asc')
            ->select();
        $this->assign('user',$user);
        $this->assign('infos',$infos);
        return $this->fetch("order/seeinfo");
    }


}